package summer.greedy;

public class Solution53 {
    public int maxSubArray(int[] nums) {
        int pre = 0;
        int res = Integer.MIN_VALUE;
        for (int num : nums) {
            if (pre < 0) {
                pre = num;
            } else {
                pre += num;
            }
            res = Math.max(res, pre);
        }
        return res;
    }
}
